package com.codehacker.job.mallservice.controller;

import com.codehacker.job.mallservice.dao.BannerMapper;
import com.codehacker.job.mallservice.dto.ResponseDTO;
import com.codehacker.job.mallservice.entity.Banner;
import com.codehacker.job.mallservice.entity.BannerExample;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * BannerController
 *
 * @author zhuyuwei
 * @date 26/07/2017
 */
@Controller
@RequestMapping("/api/banner")
public class BannerController {
    @Resource
    private BannerMapper bannerMapper;

    @RequestMapping("")
    @ResponseBody
    public ResponseDTO<Banner> queryBanner(@RequestParam("is_show") Boolean isShow) {
        ResponseDTO<Banner> result = new ResponseDTO<Banner>();
        BannerExample example = new BannerExample();
        if (!isShow) {
            result.getMeta().setCode(0);
            return result;
        } else {
            example.createCriteria().andIsShowEqualTo(1);
        }
        result.getData().getItems().addAll(bannerMapper.selectByExample(example));
        result.getMeta().setCode(0);
        return result;
    }
}
